/**
 * Created by user on 2018/11/19.
 */
import React, { createElement } from 'react'
import dynamic from 'dva/dynamic'
console.log('createElement', createElement)

const dynamicWrapper = (app, models, component) => {
  console.log('2', component.toString())
  component().then(raw => {
    // const Component = raw.default || raw;
    console.log('11', raw.default)
  });
  let ms = models.map(m => import(`@/models/${m}`))
  return dynamic({
    app,
    component: component,
    models: () => ms
  })
}

export const getRouterData = app => {
  const routerConfig = {
    '/': {
      component: dynamicWrapper(app, [], () => import('@/layouts/BaseLayout'))
    },
    '/login': {
      component: dynamicWrapper(app, ['login'], () => import('@/routes/LoginPage'))
    },
    '/dashboard/index': {
      component: dynamicWrapper(app, [], () => import('@/routes/dashboard'))
    },
    '/dashboard/test': {
      component: dynamicWrapper(app, [], () => import('@/routes/dashboard/Test'))
    },
    '/user': {
      component: dynamicWrapper(app, [], () => import('@/routes/user'))
    },
    '/about': {
      component: dynamicWrapper(app, [], () => import('@/routes/about'))
    },
    '/404': {
      component: dynamicWrapper(app, [], () => import('@/routes/Error/404'))
    }
  }
  return routerConfig
}
